package com.atwork.wuhua.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.atwork.wuhua.ConstantsMyself;
import com.atwork.wuhua.R;
import com.atwork.wuhua.adapter.MyFollowAdapter;
import com.atwork.wuhua.base.BaseActivity;
import com.atwork.wuhua.bean.MyFollowBean;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyFollowActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rv_follow)
    RecyclerView rvFollow;
    @BindView(R.id.swipe)
    SwipeRefreshLayout swipe;

    private MyFollowAdapter myFollowAdapter;
    private List<MyFollowBean> myFollowBeans;

    private String mType = "follow";// 关注 or 粉丝 页面

    public static final String FOLLOW = "follow";
    public static final String FANS = "fans";

    @Override
    protected boolean isBindEventBus() {
        return false;
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_my_follow;
    }

    @Override
    public void initView() {

        if (getIntent().getExtras() != null) {
            mType = getIntent().getExtras().getString(ConstantsMyself.INTENTTYPE);
            if (FOLLOW.equals(mType)) {
                tvTitle.setText("我的关注");
            } else {
                tvTitle.setText("我的粉丝");
            }
        }


        myFollowBeans = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            myFollowBeans.add(new MyFollowBean(i + ""));
        }

        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        rvFollow.setLayoutManager(manager);
        myFollowAdapter = new MyFollowAdapter(this, R.layout.item_my_follow, myFollowBeans);
        rvFollow.setAdapter(myFollowAdapter);

        myFollowAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.img_thumb:
                        Intent intent = new Intent(MyFollowActivity.this, PersonInfoActivity.class);
                        intent.putExtra(ConstantsMyself.INTENTID, position + "");
                        startActivity(intent);
                        break;

                    case R.id.tv_follow:
                        break;
                }
            }
        });
    }

    @Override
    public void initData() {
        swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipe.setRefreshing(false);
            }
        });
    }


    @OnClick(R.id.img_left)
    public void onViewClicked() {
        finish();
    }
}
